package com.it.sun.yuebike.base.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.it.sun.yuebike.base.model.dto.BikeInvitationDTO;
import com.it.sun.yuebike.base.model.entity.InvitationEntity;
import com.it.sun.yuebike.base.service.InvitationService;
import com.it.sun.yuebike.framework.model.dto.Result;
import com.it.sun.yuebike.framework.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sunmannian
 * @since 2021-06-05
 */
@RestController
@RequestMapping("/invitation")
@Api(tags = "骑行信息")
public class InvitationController {

    @Autowired
    private InvitationService invitationService;

    @PostMapping()
    @ApiOperation("新增骑行信息")
    public Result<Void> saveBikeInvitation(@RequestBody InvitationEntity entity) {
        return invitationService.save(entity) ? ResultUtils.success() :
                ResultUtils.error();
    }


    @GetMapping("/page")
    @ApiOperation("分页获取发布的骑行信息")
    public Result<IPage<BikeInvitationDTO>> page(Page page) {
        return invitationService.pageBikeInvitation(page);
    }


    @GetMapping("/{id}")
    @ApiOperation("分页获取发布的骑行信息")
    public Result<BikeInvitationDTO> get(@PathVariable("id") String id) {
        return invitationService.selectById(id);
    }
}

